package com.bq.gametrade.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bq.gametrade.R;
import com.bq.gametrade.bean.WithdrawalRecordsDetails;
import com.bq.gametrade.utils.Base64Util;

import java.util.ArrayList;

/**
 * Created by Feel on 2016/12/27.
 */

public class WithdrawalRecordsAdapter extends BaseAdapter {

    private ArrayList<WithdrawalRecordsDetails> mDatas;
    private Context context;

    public WithdrawalRecordsAdapter(Context context,ArrayList<WithdrawalRecordsDetails> list ) {
        this.mDatas = list;
        this.context = context;

    }

    public void setData(ArrayList<WithdrawalRecordsDetails> list) {
        this.mDatas = list;

    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view ==null){
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.listview_withdrawalrecords_itme,null);
            viewHolder.tvTime = (TextView) view.findViewById(R.id.tv_withdrawalTime);
            viewHolder.tvBankName = (TextView) view.findViewById(R.id.tv_withdrawalbankCard);
            viewHolder.tvMoney = (TextView) view.findViewById(R.id.tv_allWithdrawalMoney);
            viewHolder.tvSatus = (TextView) view.findViewById(R.id.tv_allWithdrawalStatus);
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder)view.getTag();
        }
        WithdrawalRecordsDetails details = mDatas.get(position);
        viewHolder.tvTime.setText(details.ctime);
        viewHolder.tvBankName.setText(Base64Util.decodeStr(details.bank_name)+"*"+details.card_num.substring(details.card_num.length()-4,details.card_num.length()));
        viewHolder.tvMoney.setText(details.money.replace(",",""));
        if(details.c_status.equals("0")){
            viewHolder.tvSatus.setText("已提交银行");
            viewHolder.tvSatus.setTextColor(context.getResources().getColor(R.color.tv_red));
        }else if(details.c_status.equals("1")){
            viewHolder.tvSatus.setText("提现成功");
            viewHolder.tvSatus.setTextColor(context.getResources().getColor(R.color.yellow_ff5d26));
        }else if(details.c_status.equals("2")) {
            viewHolder.tvSatus.setText("提现取消");
            viewHolder.tvSatus.setTextColor(context.getResources().getColor(R.color.color666666));
        }

        return view;
    }

    class ViewHolder{
        TextView tvTime;
        TextView tvBankName;
        TextView tvMoney;
        TextView tvSatus;
    }
}
